package benchmarks;

import benchmarks.benchmarktests.BenchmarkTest;
import helpers.DataraceException;
import helpers.RaceConditionException;
import problemfactories.IProblemFactory;

public abstract class AbstractBenchmark<TSolution>
{
    private IProblemFactory<TSolution> problemFactory;

    protected AbstractBenchmark(IProblemFactory<TSolution> problemFactory)
    {
        this.problemFactory = problemFactory;
    }

    public BenchmarkTest<TSolution> createPassingTest()
    {
        return createBenchmarkTest(problemFactory.getSolution());
    }

    public BenchmarkTest<TSolution> createTestWithDeadlock()
    {
        return createBenchmarkTest(problemFactory.getSolutionWithDeadlock());
    }

    public BenchmarkTest<TSolution> createTestWithRaceCondition() throws RaceConditionException
    {
        return createBenchmarkTest(problemFactory.getSolutionWithRaceCondition());
    }

    public BenchmarkTest<TSolution> createTestWithDatarace() throws DataraceException
    {
        return createBenchmarkTest(problemFactory.getSolutionWithDatarace());
    }

    protected abstract BenchmarkTest<TSolution> createBenchmarkTest(TSolution solution);
}
